package com.tmanager.persistence.tx;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * Method marked with this annotation will be considered for transactional.
 * <p/>
 *
 * @author Paul A. Shmarev
 */
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR})
@Retention(RetentionPolicy.RUNTIME)
public @interface Transactional {

    /**
     * Use RequiresNew when the results of the method must be committed regardless whether the
     * caller's transaction succeeds. For example, a method that logs all attempted transactions,
     * whether those transaction succeed or not, could use RequiresNew to add log entries.
     * RequiresNew always creates a new transaction context before the method call, and commits
     * or rolls back after the method call. Note that any existing client transaction context will
     * be suspended until the method call returns.
     *
     * @return true if requires new transaction
     */
    boolean requiresNew() default false;

    /**
     * A list of exceptions to rollback on, if thrown by the transactional method.
     * These exceptions are propagated correctly after a rollback.
     *
     * @return Returns the configured rollback exceptions.
     */
    Class<?>[] rollbackOn() default {Exception.class};
}
